﻿
-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Dasideen_ContentRating_GetContentRatingByContentKey') 
    BEGIN
        DROP  PROCEDURE  Dasideen_ContentRating_GetContentRatingByContentKey
    END
GO

CREATE PROCEDURE [Dasideen_ContentRating_GetContentRatingByContentKey]
-- =============================================
-- Author:		<Sagar s.k>
-- Create date: <18/04/2015>
-- Description:	<Dasideen_ContentRating_GetContentRatingByContentKey>
-- =============================================
-- Add the parameters for the stored procedure here
	(
		@ContentRatingContentKey INT 
	)
AS 
    BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
    SET NOCOUNT OFF;

    -- Insert statements for procedure here
      SELECT     
		           [ContentRatingContentKey], 
			 AVG (
				   [ContentRatingValue]
				 ) AS [AvrageRating], 

		   COUNT (
				   [ContentRatingContentKey]
				 ) AS [TotalVotes]
        
		FROM    [ContentRating]
		WHERE     
		         (
                   [ContentRatingContentKey] = @ContentRatingContentKey
                 )
        GROUP BY ContentRatingContentKey
    
	END
GO
